package com.lap.analysis.tools;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.stream.Stream;

/**
 * uri 工具
 *
 * @author Shuisheng Lao(劳水生)
 * @version 0.0.1
 */
public final class UriUtil {
  private static final String SLASH = "/";

  private UriUtil() {}

  public static String getUri(String... uris) {
    return SLASH
        + String.join(
            SLASH,
            Stream.of(uris)
                .filter(StringUtils::isNotBlank)
                .map(uri -> uri.startsWith(SLASH) ? uri.substring(1) : uri)
                .toArray(String[]::new));
  }

  public static String getFirstUri(String[] uris) {
    return ArrayUtils.isEmpty(uris)
        ? ""
        : Stream.of(uris).filter(StringUtils::isNotBlank).findFirst().orElse("");
  }
}
